package br.uece.laconi.tac.fuzzy;


public class FuzzyOperations {

	/* Logic Operators */	

	public static FuzzyNumber and(FuzzyNumber num1,	FuzzyNumber num2) {
		// Mamdani Operator		
		float r = Float.MAX_VALUE;
		
		for (float i = num1.interval[0]; i <= num1.interval[1]; i += num1.step) {
			r = Math.min(r, Math.min(num1.membershipDegree(i), num2.membershipDegree(i)));
		}
		
		for (float i = num2.interval[0]; i <= num2.interval[1]; i += num2.step) {
			r = Math.min(r, Math.min(num1.membershipDegree(i), num2.membershipDegree(i)));
		}
		
		return new CrispFuzzyNumber(r);
	}
	
	public static FuzzyNumber or(FuzzyNumber num1, FuzzyNumber num2) {
		// Mamdani Operator		
		float r = Float.MIN_VALUE;
		
		for (float i = num1.interval[0]; i <= num1.interval[1]; i += num1.step) {
			r = Math.max(r, Math.max(num1.membershipDegree(i), num2.membershipDegree(i)));
		}
		
		for (float i = num2.interval[0]; i <= num2.interval[1]; i += num2.step) {
			r = Math.max(r, Math.max(num1.membershipDegree(i), num2.membershipDegree(i)));
		}
		
		return new CrispFuzzyNumber(r);
	}
	
	public static CrispFuzzyNumber and(CrispFuzzyNumber num1, CrispFuzzyNumber num2) {
		// Mamdani Operator
		float r = Math.min(num1.value, num2.value);		
		return new CrispFuzzyNumber(r);
	}
	
	public static CrispFuzzyNumber or(CrispFuzzyNumber num1, CrispFuzzyNumber num2) {
		// Mamdani Operator
		float r = Math.max(num1.value, num2.value);		
		return new CrispFuzzyNumber(r);
	}
}
